#ifndef _LCD_ST7789_H_
#define _LCD_ST7789_H_

#include "stdc.h"
#include "nonos.h"

#define USE_HORIZONTAL 0  //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#define TITLE_OFFSET 20

#if USE_HORIZONTAL==0||USE_HORIZONTAL==1
#define LCD_W 240
#define LCD_H 240
#else
#define LCD_W 240
#define LCD_H 240
#endif


typedef void (*FUNC_spiWriteByte)(uint8_t ch);
typedef void (*FUNC_spiWrite)(uint8_t *buf, uint32_t len);

typedef struct {
	uint16_t backColor;   //背景色
	FUNC_GPIO_Out dc;
	FUNC_GPIO_Out rst;
	FUNC_spiWriteByte spiWriteByte;
	FUNC_spiWrite spiWrite;
} driver_st7789_t;

void st7789_init(driver_st7789_t *dev, uint16_t backColor, FUNC_GPIO_Out dc, FUNC_GPIO_Out rst, FUNC_spiWriteByte spiWriteByte, FUNC_spiWrite spiWrite);
void st7789_clear(driver_st7789_t *dev, uint16_t color);
void st7789_showChinese(driver_st7789_t *dev, uint16_t x, uint16_t y, uint8_t index, uint8_t size, uint16_t color);
void st7789_drawPoint(driver_st7789_t *dev, uint16_t x, uint16_t y, uint16_t color);
void st7789_fill(driver_st7789_t *dev, uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color);
void st7789_drawLine(driver_st7789_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
void st7789_drawRectangle(driver_st7789_t *dev, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,uint16_t color);
void st7789_drawCircle(driver_st7789_t *dev, uint16_t x0, uint16_t y0, uint8_t r, uint16_t color);
void st7789_showChar(driver_st7789_t *dev, uint16_t x, uint16_t y, char ch, uint8_t mode, uint16_t color);
void st7789_showString(driver_st7789_t *dev, uint16_t x, uint16_t y, const char *str, uint16_t color);
void st7789_showPicture(driver_st7789_t *dev, uint8_t *pic);

#define LCD_WHITE         	 0xFFFF
#define LCD_BLACK         	 0x0000
#define LCD_BLUE           	 0x001F
#define LCD_BRED             0XF81F
#define LCD_GRED 			 0XFFE0
#define LCD_GBLUE			 0X07FF
#define LCD_RED           	 0xF800
#define LCD_MAGENTA       	 0xF81F
#define LCD_GREEN         	 0x07E0
#define LCD_CYAN          	 0x7FFF
#define LCD_YELLOW        	 0xFFE0
#define LCD_BROWN 			 0XBC40 // 棕色
#define LCD_BRRED 			 0XFC07 // 棕红色
#define LCD_GRAY  			 0X8430 // 灰色
#define LCD_DARKBLUE      	 0X01CF	// 深蓝色
#define LCD_LIGHTBLUE      	 0X7D7C	// 浅蓝色
#define LCD_GRAYBLUE       	 0X5458 // 灰蓝色
#define LCD_LIGHTGREEN     	 0X841F // 浅绿色
#define LCD_LGRAY 			 0XC618 // 浅灰色(PANNEL),窗体背景色
#define LCD_LGRAYBLUE        0XA651 // 浅灰蓝色(中间层颜色)
#define LCD_LBBLUE           0X2B12 // 浅棕蓝色(选择条目的反色)

#endif // _LCD_ST7789_H_
